//引入一级路由组件
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//引入二级路由组件
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'

//路由配置信息
export default [
  //路由重定向
  { path: '/', redirect: '/home' },
  { path: '/home', component: Home, meta: { show: true } },
  { path: '/login', component: Login, meta: { show: false } },
  { path: '/register', component: Register, meta: { show: false } },
  { path: '/search/:keywork?', component: Search, meta: { show: true }, name: 'search' },
  { path: '/detail/:skuid', component: Detail, meta: { show: true } },
  { path: '/addcartsuccess', component: AddCartSuccess, meta: { show: true }, name: 'addcartsuccess' },
  { path: '/shopcart', component: ShopCart, meta: { show: true }, name: 'shopcart' },
  {
    path: '/pay', component: Pay, meta: { show: true },
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      //去交易页面，必须是从购物车而来
      if (from.path == "/trade") {
        next()
      }
      //如果是从其他路由组件而来，停留在当前页面
      else {
        next(false)
      }
    }
  },
  { path: '/paysuccess', component: PaySuccess, meta: { show: true } },
  {
    path: '/trade', component: Trade, meta: { show: true },
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      //去交易页面，必须是从购物车而来
      if (from.path == "/shopcart") {
        next()
      }
      //如果是从其他路由组件而来，停留在当前页面
      else {
        next(false)
      }
    }
  },
  {
    path: '/center', component: Center, meta: { show: true },
    //二级路由组件
    children: [{
      path: 'myorder',
      component: MyOrder
    },
    {
      path: 'grouporder',
      component: GroupOrder
    },
    {
      //重定向
      path: '/center',
      redirect: '/center/myorder'
    }]
  },
]
